<?php

namespace front\modules\web\controllers;


use backfeed\services\SuggestionService;
use front\controllers\WebBaseController;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * SuggestionController implements the CRUD actions for Suggestion model.
 */
class SuggestionController extends WebBaseController
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }


    /**
     * Creates a new Suggestion model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        if (Yii::$app->request->isAjax) {
            $data = Yii::$app->request->post();
            $data['user_id'] = $this->getUserId();
            $result = SuggestionService::add($data);
            if ($result['code'] == 0) {
                return 1;
            }else {
                return json_encode($result['message']);
            }
        }
        return  $this->render('create',[
        ]);
    }

}
